package com.iter.devbox.juc;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * juc 并发集合操作实例
 * 
 * @author Jimly
 *
 */
public class ConcurrentCollectionsApp {

	public static void main(String[] args) throws Throwable {
		//blockingDeque();
		threadPool();
	}
	
	/**
	 * BlockingDeque、LinkedBlockingDeque使用演示
	 */
	public static void blockingDeque () {
		BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<Integer>();
		blockingDeque.add(1);
		blockingDeque.add(2);
		blockingDeque.add(3);
		blockingDeque.add(4);
		blockingDeque.add(5);
		
		blockingDeque.addFirst(0);
		blockingDeque.addLast(6);
		
		for (int i : blockingDeque) {
			System.out.println(i);
		}
		
		blockingDeque.addFirst(0);
		blockingDeque.addLast(6);

		System.out.println(blockingDeque.getFirst());
		System.out.println(blockingDeque.getLast());
		
	}
	
	public static void threadPool () throws InterruptedException, ExecutionException {
		ExecutorService poll = Executors.newFixedThreadPool(2);
		
		poll.submit(new MyThead());
		
		poll.execute(new MyThead());
		
		poll.shutdown();
	}
}
